package com.mo.modular.tv.job;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.stereotype.Component;

@Component
@EnableScheduling
public class LiveJob {
	
	private Logger log = LoggerFactory.getLogger(this.getClass());
	private static long contId=260206180L;
	
	private static double[] baseNum = {11.6,10.8,9.9,9.5,9.1,8.6,7.8,7.3,6.5,6.0,6.0,5.6,5.2};
	
	@Autowired
    StringRedisTemplate stringRedisTemplate;
	
	
	
//	@Scheduled(cron="${baseInfo.job.addLiveCountCron}")
	public void addLiveCount(){
		/*ZlLiveTime zlLiveTime = zlLiveTimeService.selectZlLiveTimeByCId(contId);
		if(zlLiveTime!=null){
			Date startTime = zlLiveTime.getStartTime();
			Date endTime = zlLiveTime.getEndTime();
			long currentTimeMillis = System.currentTimeMillis();
			String region = zlLiveTime.getRegion();
			String[] citys = region.split(",");
			if(startTime.getTime()<=currentTimeMillis&&currentTimeMillis<=endTime.getTime()){
				LinkedHashMap<String, Double> regionInfo = contService.getOriginalLiveRegionInfo(contId,13);
				double sumCount = 0;
				Random ra =new Random();
				if(regionInfo.size()>0){
					for(int i=0;i<baseNum.length;i++){
						double count = ra.nextInt(5)+baseNum[i];
						Double cityCount = regionInfo.get(citys[i]);
						if(null==cityCount){
							cityCount=0.0;
						}
						sumCount+=cityCount+count;
						stringRedisTemplate.opsForZSet().add(String.format(TV_SYS_KEY.TV_SYS_CONT_LIVE_COUNT_INFO, contId), citys[i], cityCount+count);
					}
				}else{
					for(int i=0;i<baseNum.length;i++){
						double count = ra.nextInt(5)+baseNum[i];
						sumCount+=count;
						stringRedisTemplate.opsForZSet().add(String.format(TV_SYS_KEY.TV_SYS_CONT_LIVE_COUNT_INFO, contId), citys[i], count);
					}
				}
				stringRedisTemplate.opsForValue().set(String.format(TV_SYS_KEY.TV_SYS_CONT_LIVE_ALL_ONLINE_COUNT_INFO, contId), sumCount+"");
				log.info("快速执行在线人数------------");
			}else{
				return;
			}
		}else{
			return;
		}
		*/
		
	}
}
